package 多线程.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Test02 {
    public static void main(String[] args) {
        Thread count = new Test01.count();
        Thread time = new Test01.time();
        count.start();
        time.start();
    }
    static class count extends Thread {

        @Override
        public void run() {
            int i = 0;
            while (true){
                System.out.println("数字：" + ++i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    static class time implements Runnable {
        @Override
        public void run() {
            while (true){
                Date currentTime = new Date();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String formattedTime = formatter.format(currentTime);
                System.out.println("时间：" +formattedTime);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
